/*
 * Created by SharpDevelop.
 * User: nebulom
 * Date: 8/26/2009
 * Time: 9:09 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using Miming.Model;

namespace Miming.Gui
{
	/// <summary>
	/// Description of TermsListForm.
	/// </summary>
	public partial class TermsListForm : BaseForm
	{
		public TermsListForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			listView1.Resize += delegate { columnHeader1.Width = listView1.Width - 22; };
			newToolStripMenuItem.Click += delegate { MainForm.Instance.AddChild(new TermsForm()); };
		}
		
		[System.ComponentModel.EditorBrowsableAttribute()]
		protected override void OnActivated(EventArgs e)
		{
			base.OnActivated(e);
			Model = SessionFacade.FindAllTerms();
		}
		
		protected override void OnModelChanged(EventArgs e)
		{
			base.OnModelChanged(e);
			listView1.Items.Clear();
			foreach (Terms t in Model as IList<Terms>) {
				ListViewItem li = listView1.Items.Add(t.Name);
			}
		}
		
		void ListView1DoubleClick(object sender, EventArgs e)
		{
			if (listView1.SelectedItems.Count > 0) {
				Terms t = (Model as IList<Terms>)[listView1.SelectedItems[0].Index];
				MainForm.Instance.AddChild(new TermsForm(t), "Edit Terms");
			}
		}
	}
}
